import {
	ref,
	computed,
	reactive
} from 'vue'
import {
	defineStore
} from 'pinia'
import router from '@/router'


//组合式
export const useCounterStore = defineStore('counter', () => {
	//全局的方法：添加路由；
	const addRouteFn=(parent,name,path)=>{
		router.addRoute(parent,{
			name,
			path,
			component:()=>import(`../views/${name}.vue`)
		})
	}
	let btns=ref([])
	
	let btnsObj=computed(()=>{
		let obj={
			addFlag:false,
			addName:"",
			updateFlag:false,
			updateName:"",
			delFlag:false,
			delName:"",
		}
		btns.value.forEach(v=>{
			if(v.menuName.substring(0,2)=="添加"){
				obj.addFlag=true;
				obj.addName=v.menuName;
			}
			if(v.menuName.substring(0,2)=="修改" || v.menuName.substring(0,2)=="编辑"){
				obj.updateFlag=true;
				obj.updateName=v.menuName;
			}
			if(v.menuName.substring(0,2)=="删除"){
				obj.delFlag=true;
				obj.delName=v.menuName;
			}
		})
		// console.log(btns.value)
		return obj;
	})
	return {
		addRouteFn,
		btns,
		btnsObj
	}
})



